package com.help10000.rms.ui.activitys

import android.annotation.SuppressLint
import android.os.Bundle
import com.amir.common.api.ApiContents
import com.amir.common.beans.Prod
import com.amir.common.utils.ImageHelper
import com.amir.common.utils.MoneyEdiTextUtil
import com.amir.common.utils.ToastUtil
import com.amir.common.weight.DuplicateClickProxy
import com.help10000.rms.R
import com.help10000.rms.mvp.presenter.AddProductPresenter
import com.help10000.rms.mvp.view.AddProductView
import com.help10000.rms.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_add_product.*

/**
 * 添加商品
 */
class AddMaterialActivity : BaseActivity<AddProductPresenter, AddProductView>(), AddProductView {
    var prod: Prod? = null
    var RepairId: String? = null
    var mWareId: String? = null
    override fun getlayoutId(): Int {
        return R.layout.activity_add_product
    }

    override fun initView() {

    }

    @SuppressLint("SetTextI18n")
    override fun initData(savedInstanceState: Bundle?) {
        prod = intent.getSerializableExtra("data") as Prod
        RepairId = intent.getStringExtra("RepairId")
        mWareId = intent.getStringExtra("WareId")
        ImageHelper.displayImage(mContext, "${ApiContents.ImageUrl}${prod?.Image}", iv_image)
        tv_name.text = prod?.ItemName
        tv_style.text = prod?.ItemStyle
        MoneyEdiTextUtil.afterDotTwo(tv_price)
        tv_price.setText("${prod?.Price?.toBigDecimal()}")
        tv_unit.text = prod?.Unit

    }

    override fun initListener() {
        super.initListener()
        btn_add.setOnClickListener(DuplicateClickProxy {
            val SaleQty = et_num.text.toString().trim()
            if (SaleQty.isEmpty()) {
                ToastUtil.show("请输入数量")
                return@DuplicateClickProxy
            }
            val price = tv_price.text.toString().trim()
            if (price.isEmpty()) {
                ToastUtil.show("请输入价格")
                return@DuplicateClickProxy
            }
            mPresenter.addProduct(RepairId, prod?.ItemId, SaleQty, price, mWareId)
        })
        btn_close.setOnClickListener(DuplicateClickProxy {
            finish()
        })
    }

    override fun addSuccess() {
        finish()
    }

    override fun createPresenter(): AddProductPresenter {
        return AddProductPresenter(this)
    }
}